import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

class Request {
    public String username;
    public String password;
}

class Response {
    public String OK;
}

@WebServlet("/JsonParameterServlet")
public class JsonParameterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        ObjectMapper mapper = new ObjectMapper();
        Request request = mapper.readValue(req.getInputStream(), Request.class);
        System.out.println("password:" + request.password);
        System.out.println("username:" + request.username);

        //使用json格式来进行
        Response response = new Response();
        response.OK = "ok";
        String respJson = mapper.writeValueAsString(response);
        resp.setContentType("application/json; charset=utf-8");
        resp.getWriter().write(respJson);


    }
}
